package com.abc.util;

import com.github.promeg.pinyinhelper.Pinyin;

import java.util.Random;

public class StringUtils {
    public static String getRandomString(int length) {
        String str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        Random random = new Random();
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < length; i++) {
            int number = random.nextInt(62);
            sb.append(str.charAt(number));
        }

        return sb.toString();
    }

    public static String toPinyin(String content) {
        StringBuilder stringBuilder = new StringBuilder();
        char[] cs = content.toCharArray();
        for (char c : cs) {
            stringBuilder.append(Pinyin.toPinyin(c));
        }
        return stringBuilder.toString().toLowerCase();
    }


}
